/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.pinyin.validate;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @project-name:coffice-toolbox
 * @package-name:com.hyts.pinyin.validate
 * @author:LiBo/Alex
 * @create-date:2019-08-05 17:01
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
public class StringValidator {

    /**
     * 判断是否属于中文
     * 过滤相关的字符串中非中文的字段
     * @param str
     * @return
     */
    public static String chineseFilter(String str){
        char[] charset = str.toCharArray();
        StringBuilder word = new StringBuilder(str.length());
        for(char element:charset){
            String charStr = Character.toString(element);
            if(element > 128 && charStr.matches( "[\\u4E00-\\u9FA5]+")){
                word.append(charStr);
            }
        }
        return word.toString();
    }

    /**
     * 是否属于汉字范围
     * @param element
     * @return
     */
    public static boolean isChineseCharacter(char element){
        String charStr = Character.toString(element);
        return element > 128 && charStr.matches( "[\\u4E00-\\u9FA5]+");
    }

}
